package com.feihong.txgw.tx_model;

import com.feihong.txgw.inter.contract.location.ILocationContract;
import com.feihong.txgw.model.bean.user.SortModel;
import com.feihong.txgw.utils.cache.AbNetWorkCache;
import com.feihong.txgw.utils.cache.CacheManager;
import com.feihong.txgw.utils.helper.RxHelper;
import com.feihong.txgw.utils.manage.RetrofitManager;

import java.util.HashMap;

import io.reactivex.Observable;

/**
 * @Author wangziheng
 * @ProjectName txgw_app
 * @ClassName LocationMainMode
 * @package com.feihong.txgw.tx_model
 * @data 2018/5/7 18:08
 * @Describe
 * @Change
 */
public class LocationMainMode implements ILocationContract.ILocationMainModel {

    public static LocationMainMode create(){
        return new LocationMainMode();
    }

    @Override
    public Observable countCityHits(String regionID) {
        return RetrofitManager.getInstance().countCityHits(regionID).compose(RxHelper.rxSchedulerHelper());
    }

//    @Override
//    public Observable<String> getAllCity() {
//        return RetrofitManager.getInstance().getAllCityInfoToLocation(new HashMap<String,String>()).compose(RxHelper.<String>rxSchedulerHelper());
//    }


    @Override
    public Observable<SortModel> getAllCity() {
        AbNetWorkCache<SortModel> abNetWorkCache = new AbNetWorkCache<SortModel>() {
            @Override
            public Observable<SortModel> get(String key, Class<SortModel> cls) {
                return RetrofitManager.getInstance().getAllCityInfoToLocation(new HashMap<String,String>()).compose(RxHelper.<SortModel>rxSchedulerHelper());
            }
        };
         Observable<SortModel> sortModelObservable = CacheManager.getInstance().load("location_sort_city_model",SortModel.class,abNetWorkCache);
         return sortModelObservable;
    }
}
